cmake_minimum_required(VERSION 3.20)

project(PipePig VERSION 0.1 LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if (POLICY CMP0167)
    cmake_policy(SET CMP0167 NEW)
endif ()

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Core Charts)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Core Charts)

set(CONTROLLER
    controller/generic_controller.cpp
    controller/generic_controller.h
)

set(PANEL
    panel/control_panel.h
    panel/control_panel.cpp
)

set(PRESENTATION
    viewcore/defines/view_core_def.h
    viewcore/window/ndt_scan_window.h
    viewcore/window/ndt_scan_window.cpp
    viewcore/view/ndt_base_view.h
    viewcore/view/ndt_base_view.cpp
    viewcore/item/rulebar.h
    viewcore/item/rulebar.cpp
    viewcore/item/ruler_types.h
    viewcore/item/ruler_manager.h
    viewcore/item/ruler_manager.cpp
    viewcore/scene/ndt_base_scene.h
    viewcore/scene/ndt_base_scene.cpp
    viewcore/scene/ndt_scan_scene.h
    viewcore/scene/ndt_scan_scene.cpp
    viewcore/view/ndt_scan_view.h
    viewcore/view/ndt_scan_view.cpp
)

set(DATA
    scan/data_seq.h
    scan/data_seq.cpp
    scan/dscan.h
    scan/dscan.cpp
    scan/cscan.h
    scan/cscan.cpp
    scan/sscan.h
    scan/sscan.cpp
    scan/ascan.h
    scan/ascan.cpp
    scan/data.h
    scan/data.cpp
    scan/props.h
    scan/props.cpp
)

set(PROJECT_SOURCES
    ${PRESENTATION}
    ${DATA}
    ${CONTROLLER}
    ${PANEL}
    view_data.h
    view_data.cpp
    pig.cpp
    pig.h
    pig.ui
    main.cpp
)

qt_add_executable(${PROJECT_NAME}
    MANUAL_FINALIZATION
    ${PROJECT_SOURCES}
)

target_link_libraries(${PROJECT_NAME} PRIVATE
    Qt${QT_VERSION_MAJOR}::Widgets
    Qt${QT_VERSION_MAJOR}::Charts
    Qt${QT_VERSION_MAJOR}::Core
)

target_include_directories(${PROJECT_NAME} PRIVATE
    controller
    scan
    viewcore
    panel
    viewcore/defines
    viewcore/item
    viewcore/scene
    viewcore/view
    viewcore/window
)

set(TARGET_NAME ${PROJECT_NAME})
include(${EINTIK_FRAMEWORK_ROOT}/scripts/eintik_core_libraries.cmake)
include(${EINTIK_FRAMEWORK_ROOT}/scripts/eintik_framework_libraries.cmake)

target_include_directories(${PROJECT_NAME} PRIVATE "./")

if (WIN32)
    target_compile_options(${PROJECT_NAME} PRIVATE /wd4251)
endif ()

if (QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(${PROJECT_NAME})
endif ()

if (BUILD_QT_CREATOR)
    set(DLL_DEST "${CMAKE_BINARY_DIR}")
else ()
    set(DLL_DEST "${CMAKE_BINARY_DIR}/test/${PROJECT_NAME}/${CONFIG_TYPE}")
endif ()

if (WIN32)
    include(${CMAKE_SOURCE_DIR}/scripts/copy_dlls.cmake)
    set(DLL_SOURCE "${CMAKE_SOURCE_DIR}/libraries/bin/${PLATFORM}/${CONFIG_TYPE}")
    copy_runtime_dlls(${PROJECT_NAME} ${DLL_SOURCE} ${DLL_DEST})
    message(STATUS ${DLL_SOURCE})

    message(STATUS ${DLL_DEST})
endif ()

if(WIN32)
    target_link_libraries(${PROJECT_NAME} PRIVATE Dbghelp)
endif()

target_link_options(${PROJECT_NAME} PRIVATE
    "-Wl,-rpath,$ORIGIN/lib"
)

find_package(Boost REQUIRED COMPONENTS json)
target_link_libraries(${PROJECT_NAME} PRIVATE Boost::json)